// pages/equipment/equipment.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    refreshed: true, // 将本属性设置为true，收起下拉刷新，可多次设置为true（即便原来已经是true了）
    skeleton: true, // 骨架屏
    bottomLoad: false,
    popShow: false,
    selectShow: false,
    disableBottomLoad: false,
    list: [],
    params: {},
    openProp: '',
    moreOptions: [
      {label: '设备型号', prop: 'model'},
      {label: '测试选项1', prop: 'model1'},
      {label: '测试选项2', prop: 'model2'},
      {label: '测试选项3', prop: 'model3'},
      {label: '测试选项4', prop: 'model4'},
    ],
    columns: [],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.refresh();
  },
  switchPop() {
    this.setData({
      popShow: !this.data.popShow
    })
  },
  reset() {
    this.setData({
      params: {}
    }, () => {
      this.seek();
    })
  },
  seek() {
    this.switchPop();
    this.refresh();
  },
  switchSelect() {
    this.setData({
      selectShow: !this.data.selectShow
    })
  },
  opSelect({target}) {
    this.setData({
      openProp: target.dataset.prop,
      columns: [
        {text: '测试选项1', value: 1},
        {text: '测试选项2', value: 2},
        {text: '测试选项3', value: 3},
        {text: '测试选项4', value: 4},
      ]
    }, () => this.switchSelect())
  },
  selectConfirm({detail}) {
    let params = {};
    params[this.data.openProp] = detail.value;
    this.setData({
        params: {
          ...this.data.params,
          ...params
        }
    }, () => this.switchSelect())
  },
  goInfo() {
    wx.navigateTo({
      url: '../equipmentInfo/equipmentInfo',
    })
  },
  refresh() {
    this.setData({
      skeleton: true
    });
    this.getData();
  },
  goMaps() {
    wx.navigateTo({
      url: '../equipmentMap/equipmentMap',
    })
  },
  // 请求数据接口
  getData() {
    let mockData = [];
    for (let index = 0; index < 15; index++) {
      mockData.push({
        title: '测试设备' + (index + 1),
        subTitle: '型号' + (index + 1),
        subTitle1: '设备描述' + (index + 1)
      })
    }
    setTimeout(() => {
      this.setData({
        list: mockData,
        disableBottomLoad: true,
        bottomLoad: false,
        skeleton: false,
        refreshed: true,
      });
    }, 1000)
  },
})